<template>
  <div class="ii-wrap">
    <div class="ii-wrap-left">
      <div class="ii-wrap-left-item">
        <!-- <img :class="(promoteIndex === 0 && showItem) ? 'img-animate' : '' " src="~assets/images/sel-arrow.png"> -->
        <p class="p1" :class="promoteIndex === 0 ? 'ii-line-active && ii-bg-active': ''" @click="toggleOneIndex(0)">热销商品
          <i :class="(promoteIndex === 0 && showItem) ? 'icon-animate' : '' " class="icon iconxiala-copy"></i>
        </p>  
        <transition name="fade">
          <div class="showColumn" v-show="promoteIndex === 0 && showItem">
            <p class="p2" :class="promoteIndex === 0 && promoteTwoIndex === 0 ? 'ii-text-active': ''" @click="toggleTwoIndex(0,0)">我要选货</p>
            <p class="p2 p3" :class="promoteIndex === 0 && promoteTwoIndex === 1 ? 'ii-text-active': ''" @click="toggleTwoIndex(0,1)">商家活动</p>
          </div>
        </transition>
      </div>
      <div class="ii-wrap-left-item">
        <!-- <img :class="(promoteIndex === 1 && showItem) ? 'img-animate' : '' " src="~assets/images/sel-arrow.png"> -->
        <p class="p1"  :class="promoteIndex === 1 ? 'ii-line-active && ii-bg-active': ''" @click="toggleOneIndex(1)">已选商品
          <i :class="(promoteIndex === 1 && showItem) ? 'icon-animate' : '' " class="icon iconxiala-copy"></i>
        </p>
        <transition name="fade">
          <div class="showColumn" v-show="promoteIndex === 1 && showItem">
            <p class="p2"  :class="promoteIndex === 1 && promoteTwoIndex === 10 ? 'ii-text-active': ''" @click="toggleTwoIndex(1,10)">我的选品</p>
            <p class="p2 p3" :class="promoteIndex === 1 && promoteTwoIndex === 11 ? 'ii-text-active': ''" @click="toggleTwoIndex(1,11)">寄样管理</p>
          </div>
        </transition>
      </div>  
      <div class="ii-wrap-left-last" :class="promoteIndex === 2  ? 'ii-line-active && ii-text-active && ii-bg-active': ''" @click="toggleOneIndex(2)">我的团单</div>
      <!-- <div class="ii-wrap-left-last" :class="promoteIndex === 3  ? 'ii-line-active && ii-text-active && ii-bg-active': ''" @click="toggleOneIndex(3)">直播热词</div>
      <div class="ii-wrap-left-last" :class="promoteIndex === 4  ? 'ii-line-active && ii-text-active && ii-bg-active': ''" @click="toggleOneIndex(4)">聊天话题</div>
      <div class="ii-wrap-left-last" :class="promoteIndex === 5  ? 'ii-line-active && ii-text-active && ii-bg-active': ''" @click="toggleOneIndex(5)">红人解析</div> -->
    </div>
    <div class="li-wrap-right" v-loading="loading">
      <nuxt-child/>
    </div>
  </div>
</template>
<script>
export default {
  async fetch({store}) {
    await store.commit('setInterIndex', 3) //保存顶级导航的路由状态
  },
  layout: 'internalouts', 
  components: {
    
  },
  computed: { //vuex保留状态
    promoteIndex() { //一级菜单
      return this.$store.state.promoteIndex
    },
    promoteTwoIndex() {
      return this.$store.state.promoteTwoIndex
    }
  },
  data() {
    return {
      index: 0, // 一级菜单
      selectIndex: 0, // 二级菜单
      // his: '',
      showItem:false, //展示列表
      sortType:0,//默认排序id
      goodsList: [], //商品列表
      loading:false,  //请求加载
      page:1, //第一页
      pages:100,  //总的页数
      searchText:'', //搜索
      priceMax:'',  //最大价格区间
      priceMin:'', //最小价格区间
      cateId:'',  //分类ID
      // showItemArr: [false, false],
      // showItemArr1: [false, false],
    }
  },
  created(){
    this.showItem = true //页面刚进来是打开的
  },
  beforeDestroy() { //离开前时销毁。一二级重置为0
    this.$store.commit('setPromoteIndex', 0);
    this.$store.commit('setPromoteTwoIndex', 0);
  },
  watch:{
    priceMin(newValue){
      this.priceMin = newValue.replace(/\D/g,'')
    },
    priceMax(newValue){
      this.priceMax = newValue.replace(/\D/g,'')
    },
  },
  methods: {
    // 二级菜单的子级一级菜单 控制toggle动态效果，一级菜单控制切换和动态效果切换
    toggleOneIndex(index) {
      if (index === 0) {
        if (this.promoteIndex === 0) {  //二级菜单等于0可以toggle 切换
          this.showItem = !this.showItem; //true表示展示列表，false 表示收起列表
        } else {
          this.showItem = true
        }
      } else if (index === 1) { 
        if (this.promoteIndex === 1) {
          this.showItem = !this.showItem;
        } else {
          this.showItem = true
        }
      } else if (index === 2){ //单独的一级菜单就给其它菜单关闭了
        this.showItem = false
        this.go('/pickGoodsHall/myorder')
        this.$store.commit('setPromoteTwoIndex', -1); //销毁路由状态，不让其选中二级菜单
      }
      //  else if (index === 3) {
      //   this.showItem = false //进入让其收起
      //   this.go('/pickGoodsHall/hotWords')
      //   this.$store.commit('setPromoteTwoIndex', -1) //销毁路由状态，不让其选中二级菜单
      // } else if (index === 4) {
      //   this.showItem = false //进入让其收起
      //   this.go('/pickGoodsHall/topic')
      //   this.$store.commit('setPromoteTwoIndex', -1) //销毁路由状态，不让其选中二级菜单
      // } else if(index === 5) {
      //   this.showItem = false //进入让其收起
      //   this.go('/pickGoodsHall/hotPeople')
      //   this.$store.commit('setPromoteTwoIndex', -1) //销毁路由状态，不让其选中二级菜单
      // }
      this.$store.commit('setPromoteIndex', index)
    },
    // 二级菜单 控制跳转路由
    toggleTwoIndex(index, twoIndex) {
      this.$store.commit('setPromoteTwoIndex', twoIndex)
      // if(index === 0 && twoIndex === 0) {
      //   this.go('/pickGoodsHall/hotGoods')
      // } else
       if(index === 0 && twoIndex === 1) {
        this.go('/pickGoodsHall/shopActivies')
      } else if (index === 1 && twoIndex === 10) {
        this.go('/pickGoodsHall/selectedShop')
      } else if(index === 1 && twoIndex === 11) {
        this.go('/pickGoodsHall/goodsManagement')
      }
    },
     hotsList(){ //我要选货商品列表goodsList
      this.loading = true
      let params ={
        pageNum:this.page, //页码数
        skuName:this.searchText, //商品名称
        sortType:this.sortType,  //排序类型
        priceMax:this.priceMax,  //最大价格区间
        priceMin:this.priceMin,  //最小价格区间
        cateId:this.cateId, //商品分类ID 要么不写传所有的，要么就是传递某一个
      }
      this.$axios.$post('hotsList',params).then(res => {
        this.loading = false
        if(res.status === 200 ){
          this.goodsList = res.obj.list
        }else{
          this.$message({
            message:res.msg,  
            type:'warning'
          })
         }
      })
      .catch(error => {
        this.$message({
          message:'请求失败',  
          type:'warning'
        })
      })
    },
    goodsCateList(){ //商品信息之分类列表
      this.$axios.$post('goodsCateList').then(res => {
        if(res.status === 200 ){
          this.typeList = res.obj
        }else{
          this.$message({
            message:res.msg,  
            type:'warning'
          })
         }
      })
      .catch(error => {
        this.$message({
          message:'请求失败',  
          type:'warning'
        })
      })
    },
    mounted(){
      this.goodsCateList(); //商品信息之分类列表
      this.hotsList();  //我要选货商品列表
    },
  }
}
</script>

<style scoped>
  .ii-wrap {
    display: flex;
    justify-content: space-between;
    min-width:1200px;
  }
  .ii-wrap-left {
    background: #efefef;
    width: 220px;
    border-radius: 4px;
    box-shadow:0 -4px 5px #f4f4f4;
    /* margin-bottom:20px; */
  }
  .li-wrap-right {
    flex:1;
    margin: 20px;
  }
  .ii-wrap-left-one {
    height: 50px;
    border-bottom: 1px solid #f4f4f4;
    line-height: 50px;
    padding-left: 30px;
    font-size: 14px;
    color: #333;
    cursor: pointer;
    position: relative;
    user-select: none;
  }
  .ii-wrap-left-item {
    border-bottom: 1px solid #f4f4f4;
    user-select: none;
    position:relative;
  }
  .ii-wrap-left-item p {
    cursor: pointer;
  }
  .ii-wrap-left-item .icon {
    font-style: normal;
    font-size: 28px;
    position: absolute;
    top: 0px;
    right: 9px;
    z-index: 2;
    transition: all .5s;
    color: #777777;
  }
  .icon-animate{
    transform:rotate(-180deg);
  }
  .fade-enter{
    max-height:0;
    opacity:0;
  }
  .fade-enter-to{
    max-height:68px;
    opacity:1
  }
  .fade-enter-active{
    transition:all .5s;
  }
  .fade-leave{
    max-height:68px;
    opacity:1
  }
  .fade-leave-to{
    max-height:0px;
    opacity:0
  }
  .fade-leave-active{
    transition:all .5s
  }
  .ii-wrap-left-item .p1 {
    font-size: 14px;
    color: #333;
    position: relative;
    height: 50px;
    line-height: 50px;
    padding-left: 30px;
  }
  .ii-wrap-left-item .p2 {
    font-size: 14px;
    color: #666;
    padding-left: 30px;
    margin-top:12px;
  }
 .ii-wrap-left-item .p3 {
   margin-top: 20px;
   margin-bottom: 20px;
  }
  .ii-wrap-left-last {
    height: 50px;
    line-height: 50px;
    padding-left: 30px;
    font-size: 14px;
    color: #333;
    cursor: pointer;
    position: relative;
    border-bottom: 1px solid #f4f4f4;
  }
  .ii-line-active::before {
    content: '';
    width: 3px;
    height: 26px;
    background: #0096e6;
    position: absolute;
    left: 0;
    top: 12px;
  }
  .ii-text-active {
    color: #0096e6 !important;
  }
  .ii-bg-active{
    width: 220px;
    height: 50px;
    background: #e6e6e6;
    box-sizing: border-box;
  }
</style>
